<?php
namespace Yzadmin\Controller;
use Think\Controller;
class CateController extends CkController
{
   //分类首页
   public function index()
   { 
     $data['cate']=M("Cate")->where("look=0")->order("sort asc,id asc")->select();
     $data['title']="分类管理";
     $this->assign($data);
     $this->display();
   }    
   
   //添加分类
   public function add()
   {
     $data['title']="添加分类";
     $this->assign($data);
     $this->display();     
   }
   
   
   //添加分类处理
   public function adds()
   {
     $data=I("post.");
     $cate=D("Cate");
     if(!$cate->create($data)){ 
        $this->error($cate->getError());
     }else{ 
        if($cate->add($data)){
        $this->success("分类添加成功!",U("Cate/index"));
        }else{
        $this->error("添加失败错误码:".mysql_error());
        }
     }
   }


   //修改分类
   public function update()
   {
     $id=(int)I('get.id');
     $data['cate']=M('cate')->find($id);
     $data['title']="分类修改";
     $this->assign($data);
     $this->display();
   }
   

   //修改分类处理
   public function updates()
   {
     $data=I("post.");
     $cate=D("Cate");
     if(!$cate->create($data)){ 
        $this->error($cate->getError());
     }else{ 
        if($cate->where('id='.$data['id'])->save($data)!==false){
        $this->success("分类更新成功!",U("Cate/index"));
        }else{
        $this->error("分类更新失败错误码:".mysql_error());
        }
     }
   }


   //删除分类
   public function del()
   {
     $id=(int)I('get.id');
     $data=M("Cate")->where(array('id'=>$id))->delete();
     if($data!==false)
     {
        $this->success("删除成功!");
     }else
     {  
        $error=mysql_error();
        $this->error("删除失败!错误状态码:".$error);
     }
   }


   
}